<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>护理不良事件上报粗略表</title>
  <link rel="stylesheet" href="../layui/css/layui.css">
  <script src="../layui/layui.js"></script>
</head>
<body>

<div class="site-text" style="margin: 5%; display: none" id="check"  target="test123">
  <form class="layui-form" lay-filter="FormLoad" id="event">
    <table border='1px' width='100%' cellpadding='0' id="used">
    </table>
    <div class="layui-form-item" id="button" style="display: none">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="save1">暂存</button>
        <button class="layui-btn" lay-submit lay-filter="save2">提交</button>
      </div>
    </div>
  </form>
</div>

<form class="layui-form" style="margin: 20px;text-align:center ">
  <div class="layui-form-item" style="">
    <div class="layui-inline" style="margin-top: 10px">
      <div class="layui-input-block" >
        <button class="layui-btn" lay-submit lay-filter="*">查询</button>
      </div>
    </div>
    <div class="layui-inline" style="margin-top: 10px">
      <label class="layui-form-label">状态查询： </label>
      <div class="layui-input-inline" >
        <select name="modules" id="test" lay-filter="test" lay-search="" lay-verify="">
          <option value="0" selected></option>
          <option value="1">草稿</option>
          <option value="2">已提交</option>
        </select>
      </div>
    </div>
    <div class="layui-inline" style="margin-top: 10px">
      <label class="layui-form-label">部门： </label>
      <div class="layui-input-inline" >
        <select name="modules" id="test0" lay-filter="test0" lay-search="" lay-verify="">
          <option value="0" selected></option>
          <option value="1">产科</option>
          <option value="2">护理科</option>
          <option value="3">院感科</option>
        </select>
      </div>
    </div>
    <!--        <div class="layui-inline" style="margin-top: 10px">-->
    <!--            <label class="layui-form-label">伤害程度： </label>-->
    <!--            <div class="layui-input-inline" style="">-->
    <!--                <select name="modules" id="test1" lay-filter="test1" lay-search="" lay-verify="">-->
    <!--                    <option value="0" selected>无</option>-->
    <!--                    <option value="1">A,没有，仅有导致伤害的潜在因素，存在不安全条件</option>-->
    <!--                    <option value="2">B.没有，事件差一点导致伤害但被及时避免，有可能导致伤害但没有延及病人</option>-->
    <!--                    <option value="3">C.没有，事件延及病人但没有造成伤害</option>-->
    <!--                    <option value="4">D、是的，一般伤害(密切监护，积极干预后对病人未造成不良后果)</option>-->
    <!--                    <option value="5">E、其他</option>-->
    <!--                </select>-->
    <!--            </div>-->
    <!--        </div>-->
    <!--        <div class="layui-inline" style="margin-top: 10px">-->
    <!--            <label class="layui-form-label">处理人： </label>-->
    <!--            <div class="layui-input-inline" style="" >-->
    <!--                <input name="name" value="无" id="test2" type="text" class="layui-input">-->
    <!--            </div>-->
    <!--        </div>-->
    <div class="layui-inline" style="margin-top: 10px">
      <label class="layui-form-label">报告日期： </label>
      <div class="layui-input-inline" style="" >
        <input name="date" value="" id="test3" type="text" class="layui-input">
      </div>
    </div>
    <div class="layui-inline" style="margin-top: 10px">
      <label class="layui-form-label">报告人： </label>
      <div class="layui-input-inline" style="" >
        <input name="name" value="" id="test4" type="text" class="layui-input">
      </div>
    </div>
  </div>

</form>
<table id="demo" lay-filter="test"></table>

</body>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="select">查看</a>
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="update">修改</a>
</script>

<script type="text/html" id="index">
  {{d.LAY_TABLE_INDEX+1}}
</script>
<script>

  function getQueryVariable(variable)
  {
    let query = window.location.search.substring(1);
    let vars = query.split("&");
    for (let i=0;i<vars.length;i++) {
      let pair = vars[i].split("=");
      if(pair[0] == variable){return pair[1];}
    }
    return(false);
  }
  layui.use(['table','form','jquery','layer','laydate'], function(){
    let table = layui.table;
    let form = layui.form;
    let $ = layui.$;
    let layer = layui.layer;
    let laydate = layui.laydate;
    let router = layui.router();
    laydate.render({
      elem: '#test3' //指定元素
      , type: 'date'
    });
    // 获取地址的中的值
    let user_code=decodeURIComponent(getQueryVariable("user_code"));
    let user_name=decodeURIComponent(getQueryVariable("user_name"));
    let dept_code=decodeURIComponent(getQueryVariable("dept_code"));
    let dept_name=decodeURIComponent(getQueryVariable("dept_name"));
    // layui data 保存数据
    if( user_code=="undefined"){
      console.log(layui.data('user').userinfo.user_name)
    } else{
      console.log(user_code);
      console.log("地址有值")
      layui.data('user', {
        key: 'userinfo',
        value:
          {
            user_name: user_name,
            user_code: user_code,
            dept_code:dept_code,
            dept_name:dept_name
          }
      });
      console.log(layui.data('user').userinfo.user_name)
    }
    let reporter_code = layui.data('user').userinfo.user_code;
    // let reporter_dept = layui.data('user').userinfo.dept_name.replace(/\"/g, "");
    //表格渲染
    table.render({
      elem: '#demo'
      ,height: 312
      ,url: '/Zz/My_event/selectRough?event_code=12&name='+reporter_code //数据接口
      ,page: true //开启分页
      ,cols: [[ //表头
        {title: '序号', fixed: 'left', fixed: 'left', templet: '#index'}
        ,{field: 'reporter_department', title: '科室'}
        ,{field: 'witness', title: '当事人'}
        ,{field: 'patient_name', title: '患者名字'}
        ,{field: 'kind_name', title: '事件种类'}
        ,{field: 'status_name', title: '事件状态'}
        ,{fixed: 'right', title:'操作', align:'center', toolbar: '#barDemo'}
      ]],
    });
    //监听工具条
    table.on('tool(test)', function(obj){
      let layEvent = obj.event;
      if(layEvent === 'select'){
        let url ="http://172.16.88.106:8080/select/HLBL_select_event.html?form_code="+obj.data.form_code;
        window.location=url;
      } else if(layEvent === 'update') {
        if (obj.data.event_status == 1) {
          let url ="http://172.16.88.106:8080/update/HLBL_update_event.html?form_code="+obj.data.form_code;
          window.location=url;
        } else {
          layer.open({
            title: '警告'
            , content: '你已提交，不可更改'
            , yes: function (index, layero) {
              location.reload();
            }
          });
        }
      }
    });
    let number = ["", "", "", ""];
    //选择框监听
    form.on('select(test)', function (data) {
      // number[0] = data.elem[data.elem.selectedIndex].text;
      if (data.value == 0)
        number[0] = " ";
      else
        number[0] = data.value;
      // console.log(number[0]);
    });
    form.on('select(test0)', function (data) {
      number[1] = data.elem[data.elem.selectedIndex].text;
      console.log(number[1]);
    });
    // form.on('select(test1)', function (data) {
    //     number[2] = data.elem[data.elem.selectedIndex].text;
    // });
    //查询按钮监听
    form.on('submit(*)', function (data) {
       //let i = 0;
      //console.log(data.field.name);
      number[2] = data.field.date;
      number[3] = data.field.name;
       // while(number[i]!=null&&number[i]=="无")
       // {
       //     console.log(number[i]);
       //       number[i]="";
       //       i++;
       // }
      table.render({
        elem: '#demo'
        ,
        height: 312
        ,
        url: '/Zz/My_event/select?event_code=12'+'&name='+reporter_code+'&status='+number[0]+'&dept_name=' + number[1]+'&report_date='+number[2]+'&reporter='+number[3] //数据接口
        ,
        page: true //开启分页
        ,
        cols:[[ //表头
          {title: '序号', fixed: 'left', fixed: 'left', templet: '#index'}
          ,{field: 'reporter_department', title: '科室'}
          ,{field: 'witness', title: '当事人'}
          ,{field: 'patient_name', title: '患者名字'}
          ,{field: 'kind_name', title: '事件种类'}
          ,{field: 'status_name', title: '事件状态'}
          ,{fixed: 'right', title:'操作', align:'center', toolbar: '#barDemo'}
        ]],
      });
      return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    //表单重载
    form.render();
  });
</script>

</html>